package cn.itcast.consumer.cleient;

import cn.itcast.consumer.pojo.User;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@Component
//Hystix的默认超时时长为1
@FeignClient(value = "user-service",fallback = UserClient.UserClientFallback.class)  //声明这是一个客户端  同时通过value属性指定服务名称
public interface UserClient {

    @GetMapping("/user/{id}")
    User queryById(@PathVariable("id") Long id);


    @Component
    class UserClientFallback implements UserClient{

        @Override
        public User queryById(Long id) {
            User user = new User();
            user.setId(id);
            user.setName("用户查询出现异常！");
            return user;
        }
    }
}
